
import axios from 'axios'

const HOST = 'http://47.96.162.249:8080/whgh/';

const URL = {
    mapItems: "resource/mapresource/getItems",
    mapParams: "system/mapparams/getItem"
}

const request = {
    axios:function(opt){
        let url = /\/\//.test(opt.url)?opt.url : HOST+opt.url;
        axios({
            method: opt.type || 'get',
            url: url,
            params: opt.data || {},
            // withCredentials: true,
            timeout: opt.timeout || 1000
        }).then((response) => {
            if (opt && typeof opt.success === 'function') {
                opt.success(response.data);
            }
        }, (err) => {
            if (opt && typeof opt.error === 'function') {
                opt.error(err);
            }
        })
    },
    getMapItems: function(opt) {
        this.axios({
            url: URL.mapItems,
            data: {
                // isPrivate:true
            },
            success: (data) => {
                if (opt && typeof opt.success === 'function') {
                    opt.success(data);
                }
            },
            error: (e) => {
                if (opt && typeof opt.error === 'function') {
                    opt.error(e);
                }
            }
        })
    },
    getMapParams: function(opt) {
        this.axios({
            url: URL.mapParams,
            data:{},
            success: (data) => {
                if (opt && typeof opt.success === 'function') {
                    opt.success(data);
                }
            },
            error: (e) => {
                if (opt && typeof opt.error === 'function') {
                    opt.error(e);
                }
            }
        })
    },
    getServerInfo: function(mapUrl, successFun) {
        this.axios({
            url: mapUrl,
            data: {
                f:'pjson'
            },
            success: successFun
        })
    },

}

export default request